package com.abbas.CayTcore.ui

import android.app.Dialog
import android.app.ProgressDialog
import androidx.appcompat.app.ActionBarDrawerToggle
import com.abbas.CayTcore.CoreApp
import com.abbas.CayTcore.R
import com.abbas.CayTcore.base.BaseActivity
import com.abbas.CayTcore.data.CoreOriginData
import com.abbas.CayTcore.databinding.ActivityMainBinding
import com.abbas.CayTcore.presenter.MainPresenter
import com.abbas.CayTcore.startActivity
import com.abbas.CayTcore.view.ViewContract

class MainActivity : BaseActivity<ViewContract.MainActivityView,MainPresenter,ActivityMainBinding>(),ViewContract.MainActivityView {

    override fun getViewBinding(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun initPresenter(): MainPresenter {
        return MainPresenter()
    }

    override fun initData() {
        presenter.firstInit()
    }

    override fun initEvent() {
        binding.apply {
            c1.setOnClickListener { startActivity(WindingActivity::class.java) }

            //setSupportActionBar(tool)
            val actionBarDrawerToggle = ActionBarDrawerToggle(
                this@MainActivity,
                drawer,
                //tool,
                R.string.app_name,
                R.string.app_name
            )
            drawer.addDrawerListener(actionBarDrawerToggle)
            actionBarDrawerToggle.syncState()

            navi.setNavigationItemSelectedListener{
                when(it.itemId){
                    R.id.about -> {
                        startActivity(AboutActivity::class.java)
                        true
                    }
                    else -> false
                }
            }
        }
    }

    override fun showWaitingDialog(dialog: Dialog) {
        dialog.show()
    }

    override fun dismissDialog(dialog: Dialog) {
        dialog.dismiss()
    }

//    override fun onCreateOptionsMenu(menu: Menu?): Boolean {
//        return menu.run {
//            menuInflater.inflate(R.menu.main_menu,menu)
//            true
//        }
//    }

//    override fun onOptionsItemSelected(item: MenuItem): Boolean {
//        return when(item.itemId){
//            R.id.navi ->{
//                binding.drawer.apply {
//                    if (isDrawerOpen(GravityCompat.START)) {
//                        closeDrawer(GravityCompat.START)
//                    }else{
//                        openDrawer(GravityCompat.START)
//                    }
//                }
//                true
//            }
//            else -> false
//        }
//    }

}